﻿using System.Windows.Forms;

namespace KasaTakip
{
    public class MyGridControl : DataGridView
    {
        protected override bool ProcessDialogKey(Keys keyData)
        {
            Keys key = (keyData & Keys.KeyCode);
            if (key == Keys.Enter)
            {
                if (this.CurrentCell != null)
                    if (this.CurrentCell.ColumnIndex != this.Columns.Count - 1)
                        return this.ProcessRightKey(keyData);
                    else
                        if (this[0, this.CurrentCell.RowIndex].Visible)
                            this.CurrentCell = this[0, this.CurrentCell.RowIndex];
                        else
                            this.CurrentCell = this[1, this.CurrentCell.RowIndex];
            }
            return base.ProcessDialogKey(keyData);
        }
        protected override bool ProcessDataGridViewKey(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (this.CurrentCell != null)
                    if (this.CurrentCell.ColumnIndex != this.Columns.Count - 1)
                        return this.ProcessRightKey(e.KeyData);
                    else
                    {
                        if (this[0, this.CurrentCell.RowIndex].Visible)
                            this.CurrentCell = this[0, this.CurrentCell.RowIndex];
                        else
                            this.CurrentCell = this[1, this.CurrentCell.RowIndex];
                    }
            }
            return base.ProcessDataGridViewKey(e);
        }
    }
}
